/*
Copyright (c) [2019年5月1日] [吴超]
[MBT_studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
#pragma once

#include "UI/Widget.h"
#include "UI/ui绘制模板.h"

#include "UI/intern/ui文本编辑.h"

#include <string>
#include <map>




class C_菜单项;




class C_菜单 : public C_Widget {
	uint32		ui_当前菜单项;
	C_Widget*	ui_Root菜单项;
	C_Widget*	ui_弹出窗口;


public:
	C_菜单(E_方向 dir, S_UI渲染环境& ctx);
	~C_菜单();

	const E_方向		m_排列方向;
	bool				m_鼠标离开关闭菜单;
	int32				m_当前焦点ID;
	
	S_Surface2D* m_背景;
	S_Surface2D* m_描边;
	S_Surface2D* m_字符;
	S_Surface2D* m_分隔线;


	C_Widget*		mui_发起组件;
	C_行编辑框*		mui_搜索框;
	S_Props			m_搜索文本;


	std::vector<C_Widget*> mui_根菜单项;
	std::vector<C_菜单项*> mui_搜索菜单项;

	void*					m_打开线程;

	static C_菜单* m_当前打开菜单;


	void f_打开(const vec2& pos, const bool 记忆 = false);
	void f_关闭();

	C_菜单项*	f_创建项(const std::u16string txt, std::u16string ico = u"", std::u16string key = u"");
	void		f_添加项(C_菜单项* item);
	void		f_移除项(C_菜单项* itme);
	void		f_设置项冻结(uint32 id, bool y);
	void		f_切换搜索菜单项(std::vector<C_菜单项>& items);
};







class C_菜单项 : public C_Widget {
	//C_Widget*	ui_根菜单;
public:
	C_菜单项(S_UI渲染环境& ctx, const std::u16string txt, const std::u16string& ico, float32 菜单厚度 = 20);
	
	
	uint32 m_背景绘制;
	uint32 m_图标绘制;
	S_Surface2D* m_标题绘制;


	std::u16string        m_主语言_标题;
	std::u16string        m_英语_标题;
	std::u16string        m_快捷键;

	bool				m_是否获取焦点;
	C_菜单*				ui_子菜单;
	fp_on_菜单项点击	mf_菜单事件;

	inline std::u16string		f_getTitle() { return m_主语言_标题; }
	
	C_菜单* f_添加子菜单(uint32 layer, S_UI渲染环境& ctx);

protected:
	void f_关闭菜单链(C_Widget* w);
};



//struct S_菜单项创建参数;
vec2 f_菜单子项坐标矫正(C_菜单项* 项);
vec2 f_菜单坐标矫正(C_菜单* 项, vec2 pos);

void f_菜单_构建动态菜单();
void f_菜单_关闭(C_菜单* menu);



class C_弹出信息框 : public C_Widget {
	
public:
	C_弹出信息框(S_UI渲染环境& ctx);
	~C_弹出信息框();

	std::vector<std::vector<std::u16string>> m_text;


	void*	m_打开线程;

};



//class C_代码提示信息框 : public C_Widget {
//
//public:
//	C_代码提示信息框(S_UI创建环境& ctx);
//
//	std::vector<std::vector<std::u16string>> m_text;
//
//};






//void f_顶层菜单画布构建(C_菜单* self, uint32 layer, S_UI创建环境& ctx);
